$(function() {
    var $menuTree = $("#menuTree");

    $menuTree.tree({
        url: _ctx + "/sysMenu/list",
        animate: true,
        idField: 'id',
        textField: 'menuName',
        parentField: 'parentId',
        dnd: false,
        cache: false,
        onClick: function (node) {
            var children = $menuTree.tree("getChildren", node.target);
            if (children.length === 0) {
                var title = node.text;
                var $easyuiTab = $("#easyui-tabs");
                if ($easyuiTab.tabs("exists", title)) {
                    $easyuiTab.tabs("select", title);
                } else {
                    var content = "页面内容未开发 !";
                    if (node.menuUrl) {
                        content = "<iframe src='" + _ctx + node.menuUrl + "' width='100%' height='100%' frameborder='0' scrolling='no'></iframe>";
                    }
                    $easyuiTab.tabs("add", {
                        title: title,
                        selected: true,
                        closable: true,
                        content: content,
                        iconCls: node.iconCls
                    });
                }
            } else {
                $menuTree.tree("toggle", node.target);
            }
        }
    });

    $("#logout").click(function() {
        window.location.href = _ctx + "/sysUser/logout";
    });
});